Make build script more robust