work on main loop