Merged Jeff's fix for nested contexts