remove duplicate matching in basic algorithm