added index updating code
simplified unindexed check