Refactor complex/duplicate method bodies

These methods essentially repeat the same body code so reduce the
duplication into something that's simpler to follow.