Refactor some of the startup code.