Deduplicate some code.