Fix error in main loop