Check for duplicate flags.

Moved check to a function and do it only once at the end of the scan.