Avoid array out-of-bounds when max search depth is reached