more refactor. more tests