corrected main loop again