Refactoring the code for better readability