worked on main loop