Fixed issue with dangling references to deleted states in matrix.