changed state destructor to operate on state object instead of lib-level globals
moved loading of pat into ts object into ts from pat
pmt - moved set state into sep method so control is from top