improved logic for preventing dups