refactor reading flag