Cleanup main loop & clarify testing code