Coalesce like paths, remove an unneeded function.
Join more code paths.

There is no reason to have two very similar code paths when one code path could do.
Coalesce all code paths for connection replacement into one.