Began to refactor structure generation code to be easier to unit test.