wholesale refactorization

Reorganize code structures, documentation, etc.
Documentation still needs work.