Refactoring and game loop