diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 9f36393d5912e3097e7621f53b97032096c869ad..7e68f476a7f3c4ae1e330daf03dbfad7fd5aca0c 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -67,7 +67,10 @@ class Hooks {
 		$session->setPrivateKey($privateKey, $params['uid']);
 
 		// Check if first-run file migration has already been performed
-		$ready = $util->beginMigration();
+		$ready = false;
+		if ($util->getMigrationStatus() === Util::MIGRATION_OPEN) {
+			$ready = $util->beginMigration();
+		}
 
 		// If migration not yet done
 		if ($ready) {
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index a5aa121f93090a715c116fafc0fc727d915d584c..f6da417c6f99db5ed617d37a02cb6d625537eba7 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -1056,64 +1056,26 @@ class Util {
 
 	}
 
-	/**
-	 * @brief Set file migration status for user
-	 * @param $status
-	 * @return bool
-	 */
-	private function setMigrationStatus($status) {
-
-		$sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ?';
-
-		$args = array(
-			$status,
-			$this->userId
-		);
-
-		$query = \OCP\DB::prepare($sql);
-
-		if ($query->execute($args)) {
-
-			return true;
-
-		} else {
-			\OCP\Util::writeLog('Encryption library', "Could not set migration status for " . $this->userId, \OCP\Util::ERROR);
-			return false;
-
-		}
-
-	}
-
 	/**
 	 * @brief start migration mode to initially encrypt users data
 	 * @return boolean
 	 */
 	public function beginMigration() {
-		
-		$return = false;
 
-		$transaction = \OC_DB::beginTransaction();
-
-		if ($transaction === false) {
-			\OCP\Util::writeLog('Encryption library', "Your database migration doesn't support transactions", \OCP\Util::WARN);
-		}
-
-		$migrationStatus = $this->getMigrationStatus();
-
-		if ($migrationStatus === self::MIGRATION_OPEN) {
+		$return = false;
 
-			$return = $this->setMigrationStatus(self::MIGRATION_IN_PROGRESS);
+		$sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ? and `migration_status` = ?';
+		$args = array(self::MIGRATION_IN_PROGRESS, $this->userId, self::MIGRATION_OPEN);
+		$query = \OCP\DB::prepare($sql);
+		$result = $query->execute($args);
+		$manipulatedRows = $result->numRows();
 
-			if ($return === true) {
-				\OCP\Util::writeLog('Encryption library', "Enter migration mode for initial encryption for user " . $this->userId, \OCP\Util::INFO);
-			} else {
-				\OCP\Util::writeLog('Encryption library', "Could not activate migration mode for " . $this->userId . ", encryption aborted", \OCP\Util::ERROR);
-			}
+		if ($manipulatedRows === 1) {
+			$return = true;
+			\OCP\Util::writeLog('Encryption library', "Start migration to encryption mode for " . $this->userId, \OCP\Util::INFO);
 		} else {
-			\OCP\Util::writeLog('Encryption library', "Another process already performs the migration for user " . $this->userId, \OCP\Util::WARN);
+			\OCP\Util::writeLog('Encryption library', "Could not activate migration mode for " . $this->userId . ". Probably another process already started the initial encryption", \OCP\Util::WARN);
 		}
-		
-		\OC_DB::commit();
 
 		return $return;
 	}
@@ -1126,29 +1088,19 @@ class Util {
 
 		$return = false;
 
-		$transaction = \OC_DB::beginTransaction();
-
-		if ($transaction === false) {
-			\OCP\Util::writeLog('Encryption library', "Your database migration doesn't support transactions", \OCP\Util::WARN);
-		}
-
-		$migrationStatus = $this->getMigrationStatus();
-
-		if ($migrationStatus === self::MIGRATION_IN_PROGRESS) {
-
-			$return = $this->setMigrationStatus(self::MIGRATION_COMPLETED);
+		$sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ? and `migration_status` = ?';
+		$args = array(self::MIGRATION_COMPLETED, $this->userId, self::MIGRATION_IN_PROGRESS);
+		$query = \OCP\DB::prepare($sql);
+		$result = $query->execute($args);
+		$manipulatedRows = $result->numRows();
 
-			if ($return === true) {
-				\OCP\Util::writeLog('Encryption library', "Leave migration mode for: " . $this->userId . " successfully.", \OCP\Util::INFO);
-			} else {
-				\OCP\Util::writeLog('Encryption library', "Could not deactivate migration mode for " . $this->userId, \OCP\Util::ERROR);
-			}
+		if ($manipulatedRows === 1) {
+			$result = true;
+			\OCP\Util::writeLog('Encryption library', "Finish migration successfully for " . $this->userId, \OCP\Util::INFO);
 		} else {
-			\OCP\Util::writeLog('Encryption library', "Someone else finished the migration mode to early for user " . $this->userId, \OCP\Util::ERROR);
+			\OCP\Util::writeLog('Encryption library', "Could not deactivate migration mode for " . $this->userId, \OCP\Util::WARN);
 		}
 
-		\OC_DB::commit();
-
 		return $return;
 	}
 
@@ -1158,7 +1110,7 @@ class Util {
 	 * @note If records are not being returned, check for a hidden space
 	 *       at the start of the uid in db
 	 */
-	private function getMigrationStatus() {
+	public function getMigrationStatus() {
 
 		$sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?';