updated pattern-matching

corrected the code and the tests