Units tests & refactoring