Add better detection of state errors