Fix bug with duplication of states