This took me too many hours in my work language to solve. Initially I next just translated it to arc, but that didn't seem to work, so I started again in arc from scratch. I sure learned a lot about arc and debugging in it.
It took me a while to wrap my mind around this problem. Sure is different than CRUD work, reports and interfaces.