Some corrections and a new function (to handle problem with overlapping index)
New test