Fixed bug with updating for state change (index out of range)