Reworked the internals of the flags library.

Added support for a three step parsing.