Add tests & refactor