massive offline refactor. very WIP. sure I messed things up in all sorts of interesting ways.