Major refactoring.  Added unit tests.
README rewrite