refactored build script and added test coverage