refactoring tests, cought few bugs