Refactored the scripts to be more succinct with loops