more generic code for toggles
merge: