Added first draft of main loop code, compiles correctly now