added a method that removes consecutive duplicates