isolate common code from a couple of previously duplicated functions