Fixed issues with statechange