Changes in function to send emails