DRY refactor some of commit b09c919.