refactoring for reduce Cyclomatic Complexity