fix bug with maxDepth