added sorted matching and matching matching
modifed with Mays edit