Rewrite in favour of dependency injection