Simplify constraints matching
Update use of sorting functions