add failsafe if statecount is undefined