Finished first draft of main loop.