improved duplicate line detection