Moved context switching to be handled in an interrupt