Refactored build scripts.
Refactored build scripts into functions.