flag refactor