Refactor building scripts