Refactor build code into method