Improve efficiency of Canonical Ordering Algorithm

Test suite passes