Major updates, looping and correction terms updated

It seems to compute the correction terms correctly, thought I haven't tested it much.
Main bottleneck is looping over all the elements and finding the maximum in each equivalence class.
(Specifically, determining which equivalence class a particular element belongs to.)
Unfortunately, it can be pretty slow on certain matrices...