rewrite for main loop