tightened main loop