2122: fixed crash caused by indexing with the wrong variable

Added a bunch of unittests, I think we cover all the cases of diffing
now.  Added a couple comments to the diffing code.