separate render loop from main loop