Separated the getEmailReport function into multiple functions
Added some comments and clarified variable names