moved tree generation to helper