refactoring into a function