Multimatch logic and general cleanup and memory clearing.
Merge pull request #717 from Gravecorp/3.1.x.x

Multimatch logic and general cleanup and memory clearing.