refactoring the code using methods