reintroduce maxDepth now that we have recursion