Optimizations in main loop and CPU usage while running in fx environment