changes code organization and splits up mailing method