Additional cleanup and better commenting of main loop