Refactoring to a method