Backend refactoring

Moved IndexedDB-specific code into modules.