Some improvements to the script, removed need to email template