Tree patterns polish

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