Hi, I would be happy to help but there's 3 problems with your request:
1. You're rewriting an (almost) perfectly fine version of ZP, any reason why you're doing that?
2. There are many sketchy parts in your code, I won't bother pointing them out if you don't give a good reason why you're re-writing ZP in the first place.
3. You should attach your resources (models/sounds/sprites) so we can test the plugin out at least...