optimized tree works (still not clean)