wrote further tests and did refactoring