finalising script and email alerts