Updated email function