refactor into a new function