Refactor task/sched switch.