Implemented unit tests - they don't all pass yet (they may have found
bugs...).