Refactoring and abstracted switching contexts