Various bug fixes in build scripts