refactoring build loop