Extracting datastores to separate modules.

Also moved common classes to the new common modules to avoid cyclic
dependencies.