refactor a bit to move helpers out for reuse