Abstract out duplicated code.