Fixed bug in buildEmail function