improved handling of state changes.