fixes entry insert when index is reverted at the same time

Hi, this commit fixes a critical problem i encountered. The value inserted at the moment when the index is inverted was wrong (the value was set as false instead of true at the moment index value was inverted from false to true)

do you have an opinion about this ?

the problem is that i am not 100% sure that this commit is good. Obviously it won't introduce a regression (this looks more robust) but i coul'nt write a test to prove the problem i encountered can be reproduced.