added function to remove duplicate consecutive states in state sequence