implemant pattern matcher with multiple match (refactoring)