Improve build script to detect errors