Added game loop logic from previous code