Refactoring the code