I hate to tell you, but I think it could be done like this:
I might have missed the point of your algorithm though…