Small refactoring to reduce complexity on main method