You are probably right LukeW. It wasn't good solution anyways, because game performance slowed down. Better solution is to adjust the code as I did above. Thanks for your reply.
Develop games in your browser. Powerful, performant & highly capable.