Refactor to resolve cyclomatic complexity Sonar issue