modify to implement pattern matching