Simplify scope switch code