fixed an error in the main loop