Cleaning up the main loop.