$evalnext is used in the $eval identifier in some way, so check out the $eval in that piece of code and see what would give strange results.

I'm not even sure why the $eval is necessary, it seems everything is evaluated the first time around...

But then again, it's a big and unreadable blob of code, so I'm not going to get a headache trying to figure it all out. My suggestion: split it up in smaller pieces, that way you get a more specific error message.