Fixed some issues with sending emails