lots of debugging done, still needs to fix a few bug in _indexing
docstring