Added code to emit user state change