Steves solution using a tree that dynamiccaly determines depth.