Here are examples showing how you might (1) coalesce two similar functions using a "mode" flag, (2) break the common code out to a third function, and (3) make one function a proper subset of another, by having one function call the other.