with comments and cleaner code
email message corrected