Started unit testing and refactoring, still a lot of work to do.
push up various stuff