replace flags array with self.state