Fixed some bugs in the build script