Adding the pattern matching code