Major fixes.  Added test suite.