refactoring and make the code more readable