refactor the code to improve readability