Code cleaning; speeding up flag status update on emails.