changed position of main while True: loop