Extract duplicate code found in two conditional branches into a separate function to improve code readability.