merge the email part to the main function