Dependency injection and minor fixes