Refactor to make it work with RavenDB