refactor into a function