refactor again to do streamlined tree parsing