Changed the way state variables are handled