Tree patterns polish

* Improved documentation for tree patterns classes
* Refactored parts of the tree patterns API to simplify classes and improve encapsulation