fixed issue with mainLoop