fix pattern matching code