refactor and more tests