some refactoring applied + tests