Refactor generator script