refactor back into a working state. some more documentation.