Update classtree.py

Refactored code a bit