more tests and refactor