refactor flag sanity checks