fix makeTree and add supporting functions