Fix some parts of for-each invariant checking.