Fixes to Pilot main loop code