fixing bug with sending emails