Add tests + refactor