rewrite of dangling switch code