Fix some bugs with email implementation