major cleanup and refactoring.
TODO's