Refactor scripts