Refactor script to be more clear