rewrite of toggle pattern