diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 13cf352b4ed604c84a92839b6976bf8032948649..e3861e7cc5a9797132c0efb2f24d19307aa400f2 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -196,7 +196,6 @@ class Hooks {
 			$sharingEnabled = \OCP\Share::isEnabled();
 
 			if ($params['itemType'] === 'folder') {
-				//list($owner, $ownerPath) = $util->getUidAndFilename($filePath);
 				$allFiles = $util->getAllFiles($path);
 			} else {
 				$allFiles = array($path);
@@ -250,13 +249,21 @@ class Hooks {
 				$userIds = array($params['shareWith']);
 			}
 
-			// If path is a folder, get all children
-			$allPaths = $util->getPaths( $path );
-			
-			foreach ( $allPaths as $path ) {
+			if ($params['itemType'] === 'folder') {
+				$allFiles = $util->getAllFiles($path);
+			} else {
+				$allFiles = array($path);
+			}
+
 			
-				// Unshare each child path
-				if ( ! Keymanager::delShareKey( $view, $userIds, $path ) ) {
+			foreach ( $allFiles as $path ) {
+
+				// check if the user still has access to the file, otherwise delete share key
+				$sharingUsers = $util->getSharingUsersArray(true, $path);
+
+				// Unshare every user who no longer has access to the file
+				$delUsers = array_diff($userIds, $sharingUsers);
+				if ( ! Keymanager::delShareKey( $view, $delUsers, $path ) ) {
 				
 					$failed[] = $path;
 					
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index e69314e099a5be2d59f38b2c92361ff1f2a0c4e0..9868aba02e81d16f758ac048252ff397cb469c30 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -693,58 +693,7 @@ class Util {
 		);
 		
 	}
-	
-	/**
-	 * @brief Expand given path to all sub files & folders
-	 * @param string $path path which needs to be updated
-	 * @return array $pathsArray all found file paths
-	 * @note Paths of directories excluded, only *file* paths are returned
-	 */
-	public function getPaths( $path ) {
 		
-		// Default return value is success
-		$result = true;
-	
-		// Make path include 'files' dir for OC_FSV operations
-		$fPath = 'files' . $path;
-		
-		// If we're handling a single file
-		if ( ! $this->view->is_dir( $fPath ) ) {
-			
-			$pathsArray[] = $path;
-			
-		// If we're handling a folder (recursively)
-		} else {
-		
-			$subFiles = $this->view->getDirectoryContent( $fPath );
-			
-			foreach ( $subFiles as $file ) {
-			
-				$filePath = substr( $file['path'], 5 );
-				
-				// If this is a nested file
-				if ( ! $this->view->is_dir( $fPath ) ) {
-					
-					// Add the file path to array
-					$pathsArray[] = $path;
-					
-				} else {
-				
-					// If this is a nested folder
-					$dirPaths = $this->getPaths( $filePath );
-					
-					// Add all subfiles & folders to the array
-					$pathsArray = array_merge( $dirPaths, $pathsArray );
-					
-				}
-			}
-			
-		}
-		
-		return $pathsArray;
-
-	}
-	
 	/**
 	 * @brief Decrypt a keyfile without knowing how it was encrypted
 	 * @param string $filePath