Refactor flag serialization out into a separate module.