index: more resilient implementation

Also adding debug() calls.
test: add a few more test cases