Canonicalization

For reviewing this code
I'm pretty sure you want the actual minimum value, not the index of the minimum value.