added optional max depth param