Selectively merged stuff from feature/context-manager.