[Refactoring] Extract code into a separate method