Fix a few bugs in build.sh