added pattern matching functionality and extra tests