Much more robust pre-build script