added configurable maximum recursion depth