Refactor copypasta into function that takes function pointer.
Refactor block of copypasta fns into single fn.
Fix merge confict.