faster checkAndReplace

still need a better solution for this uniqueId business but this is
better than before.