debugged the build function

testing now, seems to work