replaces simple "counting" flag with "state" object that can hold more states