refactor out a function