refactor build func