Canonicalization

For reviewing this code
canonical_rep = {} is the preferred idiom