Refactoring the code using Methods