correctly handle state events