intial work on the main loop