Added test cases and fixed bugs around external indexing