Getting rid of duplicates and small bug