Fully functional emailing + added more error checking and bug fixes