Working except for duplicate lines