worked on main loop. cleaned up server logic