Wrote new tree system and fixed some bugs