lots of refactoring. Added third test.