added test
more refactoring. more tests.