main loop  fix