Refactor code out to stand-alone functions. This is to support one code path