SI-7345 Refactoring Contexts

Review by @hubertp (maybe in person Tuesday afternoon?)

I've left the commits pretty fine grained to aid review, happy to squash a little bit before merge.