Refactor main loop to set up reboot.  Also some renaming.