Deduplicate three identical functions