Corrected logic with import algorithm to remove duplicate entries