fixed the output in main loop