Refactoring some of the initialization code. Incomplete.