Some refactoring and improvements to the new code implementing multiple active contexts. (Dustin, I hope you don't mind my contribution to that.)