Refactor script