Fix bug in build function