Refactored the build method.