work in progress on refactoring

compiles, but untested