in reply to how can I combine into one method

In my experience, the question how do I combine two methods is almost always the wrong question.

What is the real benefit you are trying to achieve? A lot of very bright people have discovered that making something reusable is more than twice as hard as making a single-purpose version. That's why many people don't worry about generalizing without 3 examples.

If you are going to need several more of these kinds of methods, then maybe, you have a good reason for generalizing. Even then, how do I combine is not my first question.

I normally prefer questions like:

The second question is the easiest. The third is a variation of the second. But, the first is usually the most powerful (for me).

I begin by breaking out one of these pieces into a new subroutine. I build testing code for it, to make certain it works the way I want it to. Then I modify the routines to use this chunk. In the process of building this new routine, I often find that parameter names and my variable names become more generic to fit with the utility nature of the method.

Then, I replace the code in one of the original routines with a call to the new method, running our tests to verify I haven't broken anything. (You do have tests for these methods, right? If not, you need those before you start any kind of refactoring effort.) Then I can replace functionality in the next routine, and so on.

Then, I repeat with the next chunk of code I want to break out of these methods. I apply this algorithm repeatedly until the usage of the routines becomes obvious or There's nothing more to move.

Sometimes, I will now leave the original routines in place as a simple template for running the newly refactored code. Sometimes, I will remove the old methods and replace the places they were called with calls to the new code.

I often find that just giving names to the internal functionality causes it to be reused elsewhere. This is a benefit above and beyond the desire to combine two methods. I can also build new variations of these methods by combining the common code with whatever unique data or pre/post-processing is needed.

I know this isn't a direct answer to your question, but, in my experience, it's more likely to get you to better code in the end.

G. Wade