massive refactor for build.js