updated controller and added email function