Fix bugs in "Invalid state" printing/exceptions.