Updated encoding to support flags.