refactor and new tests