Pull common state manipulation scheme into a function.