ENH: reorg more carefully based on dmat + make clearer variable names