GitHub #137: More work on context management.  Mostly working, need review and cleanup