finished first draft of main loop