refactor building script