Move context assignment to only where it is required

Moved the line to just before context is required. Tests pass.

It probably wouldn't be a bad idea to have a fuller review of this bit of code, however, I know that @ojii, is already mucking about in this bit whilst working in this bit now for a larger, upcoming change.

This closes #3106.