Optimization of gameloop