TST: move some repeated code into helper functions