update build script to use functions instead of repatition