Refine refactor

@tacaswell See "API: ..." commits.

@nkeim I may or may not make refine faster, but this refactor will make it easier if and when one of us or our successors tries. It's basically my numba commit without the numba.