Added more safeguards for failed matches. Fixed contract checking. Added sort example.