Function-ized the scripts