Deduplicated a bunch of function argument handling code.