Adding dynamic memory allocation to all the states