Added adaptive maxDepth feature