diff --git a/include/Cache.h b/include/Cache.h
index 0f6e5cd2243897c86eacc859e28f7fc7288db5f1..3a98fddc53eeecc1f0314ae0a9291d7b9834741f 100644
--- a/include/Cache.h
+++ b/include/Cache.h
@@ -35,9 +35,9 @@ public:
 
         inline void deleteData();
         inline void unmount();
-        inline QString memberDbName(const QString &roomid);
 
         void removeRoom(const QString &roomid);
+        void setup();
 
 private:
         void setNextBatchToken(lmdb::txn &txn, const QString &token);
@@ -59,15 +59,11 @@ Cache::unmount()
         isMounted_ = false;
 }
 
-inline QString
-Cache::memberDbName(const QString &roomid)
-{
-        return QString("m.%1").arg(roomid);
-}
-
 inline void
 Cache::deleteData()
 {
+        qInfo() << "Deleting cache data";
+
         if (!cacheDirectory_.isEmpty())
                 QDir(cacheDirectory_).removeRecursively();
 }
diff --git a/src/Cache.cc b/src/Cache.cc
index 5ed7708660ac8429a60487cae40a70aa62514316..c96ec37d63b743de549a183e2a9d3b6840c58bca 100644
--- a/src/Cache.cc
+++ b/src/Cache.cc
@@ -37,10 +37,21 @@ Cache::Cache(const QString &userId)
   , isMounted_{ false }
   , userId_{ userId }
 {
+}
+
+void
+Cache::setup()
+{
+        qDebug() << "Setting up cache";
+
         auto statePath = QString("%1/%2/state")
                            .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
                            .arg(QString::fromUtf8(userId_.toUtf8().toHex()));
 
+        cacheDirectory_ = QString("%1/%2")
+                            .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
+                            .arg(QString::fromUtf8(userId_.toUtf8().toHex()));
+
         bool isInitial = !QFile::exists(statePath);
 
         env_ = lmdb::env::create();
@@ -48,7 +59,7 @@ Cache::Cache(const QString &userId)
         env_.set_max_dbs(1024UL);
 
         if (isInitial) {
-                qDebug() << "[cache] First time initializing LMDB";
+                qDebug() << "First time initializing LMDB";
 
                 if (!QDir().mkpath(statePath)) {
                         throw std::runtime_error(
@@ -83,10 +94,7 @@ Cache::Cache(const QString &userId)
 
         txn.commit();
 
-        isMounted_      = true;
-        cacheDirectory_ = QString("%1/%2")
-                            .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
-                            .arg(QString::fromUtf8(userId_.toUtf8().toHex()));
+        isMounted_ = true;
 }
 
 void
@@ -156,6 +164,9 @@ Cache::insertRoomState(lmdb::txn &txn, const QString &roomid, const RoomState &s
 void
 Cache::removeRoom(const QString &roomid)
 {
+        if (!isMounted_)
+                return;
+
         auto txn = lmdb::txn::begin(env_, nullptr, 0);
 
         lmdb::dbi_del(txn, roomDb_, lmdb::val(roomid.toUtf8(), roomid.toUtf8().size()), nullptr);
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index a6a80e9d97add16584c34be3f8744ab0d9985a6c..9f983b9f37505d463ddc39072877d0c7d8a06e79 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -248,16 +248,23 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
         client_->setAccessToken(token);
         client_->getOwnProfile();
 
+        cache_ = QSharedPointer<Cache>(new Cache(userid));
+
         try {
-                cache_ = QSharedPointer<Cache>(new Cache(userid));
-        } catch (const std::exception &e) {
-                qCritical() << e.what();
+                cache_->setup();
+
+                if (cache_->isInitialized()) {
+                        loadStateFromCache();
+                        return;
+                }
+        } catch (const lmdb::error &e) {
+                qCritical() << "Cache failure" << e.what();
+                cache_->unmount();
+                cache_->deleteData();
+                qInfo() << "Falling back to initial sync ...";
         }
 
-        if (cache_->isInitialized())
-                loadStateFromCache();
-        else
-                client_->initialSync();
+        client_->initialSync();
 }
 
 void
@@ -367,6 +374,7 @@ ChatPage::syncCompleted(const SyncResponse &response)
                 qCritical() << "The cache couldn't be updated: " << e.what();
                 // TODO: Notify the user.
                 cache_->unmount();
+                cache_->deleteData();
         }
 
         client_->setNextBatchToken(response.nextBatch());
@@ -416,6 +424,7 @@ ChatPage::initialSyncCompleted(const SyncResponse &response)
         } catch (const lmdb::error &e) {
                 qCritical() << "The cache couldn't be initialized: " << e.what();
                 cache_->unmount();
+                cache_->deleteData();
         }
 
         client_->setNextBatchToken(response.nextBatch());
@@ -492,14 +501,8 @@ ChatPage::loadStateFromCache()
 {
         qDebug() << "Restoring state from cache";
 
-        try {
-                qDebug() << "Restored nextBatchToken" << cache_->nextBatchToken();
-                client_->setNextBatchToken(cache_->nextBatchToken());
-        } catch (const lmdb::error &e) {
-                qCritical() << "Failed to load next_batch_token from cache" << e.what();
-                // TODO: Clean the environment
-                return;
-        }
+        qDebug() << "Restored nextBatchToken" << cache_->nextBatchToken();
+        client_->setNextBatchToken(cache_->nextBatchToken());
 
         // Fetch all the joined room's state.
         auto rooms = cache_->states();
@@ -612,6 +615,7 @@ ChatPage::removeRoom(const QString &room_id)
                 qCritical() << "The cache couldn't be updated: " << e.what();
                 // TODO: Notify the user.
                 cache_->unmount();
+                cache_->deleteData();
         }
         room_list_->removeRoom(room_id, room_id == current_room_);
 }