Changed to an update loop and added more profiling