Refactor game-loop