some refactoring to separate the concept of shared variables under refinement checking with all global variables
more work on reducing call stack consumption