optimize dependencies
Make some refactoring and tests fix