fixing nasty bug with sending emails