sophia-index: proper iterator handling and destroy, added basic test.