Fixes for the main loop