Clean up the main loop interaction code.

It's now hidden behind a nice interface which can be changed on startup
if required.