BS-11320
Fix recursive algorithm