rewrite task switch code.