begin code for context switching