Speed Improvement in recursive functions and trees: