factor out canonicalization.py from dev branch