Merging in the big extra context pull request

This pull request is my merging-in of #260. It was quite complicated (see my comments in #260 for details), so the purpose of this PR is just to make it clear what exactly the changes are.

Since it was complicated and delicate, can another core committer please give this a quick review?