Code cleanup. Added FPS detection