some engine code and tweaks to loop.