Code cleanup, fixed email sending (made transactional)