updated insert to obtain lock only if the key is found