just for completeness it would have been possible to get what you need through "overloading" too
you could have added a boolean argument to the function signature that changes the function's behavior
but breaking up the function into more focused components is definitely the better solution