Preparations for complete RavenDB-based rewrite.

WARNING: REAL HELL OF A MESS OF A CHAOS OF A CODE.