Fixed an issue with state variable resetting to a bad value