Changed tree implementation to avoid tranversing entire tree