Set up logic for email flag.  Added debugging logic as well.