Second step of refactoring

TODO check RepositoryFactory