refactoring the method code