recovery bugfix
lots of work on removing global variables