Have ensure_similarity_limit_is_obeyed! rewrite the key to save memory, ...

...and fix an off-by-one error, and add a spec.