refactor to make code easier to understand