added setinterval() and fixed length of states