Fix many issues with memory pool
- finalize the AVL tree
- add many test cases
- simplify/cleanup code where applicible