refactor out reusable code