Factor out duplicated code/structure.