bugfixing + more robust indexing.