refactor code to improve readability