refactor the script