Refactor the script