Rewriting game loop in a better way