tests and refactor