Refactor some of the initialization code.