Add tests & refactoring