Ensure flags are not cleared when a subexpression is flushed.

Also ensure no duplicate flags.