Added uniq function to filter out successive duplicates