working on main loop