deduplicate some code