Limitted the FPS and fixed a race condition