diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 2df860a8e5772d49526e3bf8ac32f13d0c1b3ee3..d9a76becf25cfbc7527b8830e01438cfd4c4d706 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -92,8 +92,6 @@ class Hooks {
 			}
 
 			// Encrypt existing user files:
-			// This serves to upgrade old versions of the encryption
-			// app (see appinfo/spec.txt)
 			if (
 				$util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'])
 			) {
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 6f630c83a3f5b277477155e461331aaeef840a07..8621c1ba51d6199dc8c49f46a06fa1ed3cc35c03 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -38,8 +38,6 @@ class Proxy extends \OC_FileProxy {
 
 	private static $blackList = null; //mimetypes blacklisted from encryption
 
-	private static $enableEncryption = null;
-
 	/**
 	 * Check if a file requires encryption
 	 * @param string $path
@@ -49,46 +47,22 @@ class Proxy extends \OC_FileProxy {
 	 */
 	private static function shouldEncrypt($path) {
 
-		if (is_null(self::$enableEncryption)) {
-			if (
-				\OCP\App::isEnabled('files_encryption') === true
-				&& Crypt::mode() === 'server'
-			) {
-
-				self::$enableEncryption = true;
-
-			} else {
-
-				self::$enableEncryption = false;
-
-			}
-
-		}
-
-		if (!self::$enableEncryption) {
-
+		if (\OCP\App::isEnabled('files_encryption') === false || Crypt::mode() !== 'server') {
 			return false;
-
 		}
 
 		if (is_null(self::$blackList)) {
-
 			self::$blackList = explode(',', \OCP\Config::getAppValue('files_encryption', 'type_blacklist', ''));
-
 		}
 
 		if (Crypt::isCatfileContent($path)) {
-
 			return true;
-
 		}
 
 		$extension = substr($path, strrpos($path, '.') + 1);
 
 		if (array_search($extension, self::$blackList) === false) {
-
 			return true;
-
 		}
 
 		return false;
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 02955bb064e982b9020a90b788021e95c59011a0..b25ba7bb6778ed1bdc7cb4caa251bf126089c0dd 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -506,9 +506,10 @@ class Stream {
 
 				// Get all users sharing the file includes current user
 				$uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $this->relPath, $this->userId);
+				$checkedUserIds = $util->filterShareReadyUsers($uniqueUserIds);
 
 				// Fetch public keys for all sharing users
-				$publicKeys = Keymanager::getPublicKeys($this->rootView, $uniqueUserIds);
+				$publicKeys = Keymanager::getPublicKeys($this->rootView, $checkedUserIds['ready']);
 
 				// Encrypt enc key for all sharing users
 				$this->encKeyfiles = Crypt::multiKeyEncrypt($this->plainKey, $publicKeys);
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 63df0dd7dc3932db6cf10b24e59cdce9b1340873..9452dd37707fe2b98b87f28768455e5409e49ca1 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -58,6 +58,10 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
 	}
 
 	function setUp() {
+
+		//login as user1
+		\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
+
 		$this->data = 'foobar';
 		$this->view = new \OC_FilesystemView('/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1 . '/files');
 
@@ -104,9 +108,6 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase {
 	 */
 	function testCreateShare() {
 
-		//login as user1
-		\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
-
 		// share to user
 
 		// simulate a post request
diff --git a/lib/public/share.php b/lib/public/share.php
index e6a74117aa21b012cf9cb6ca33b6a388c30eb2ec..66605dafee50af99a5204717ccd5d13e3dbf5c47 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -155,13 +155,13 @@ class Share {
 
 		while ($source !== -1) {
 
-			// Fetch all shares of this file path from DB
+			// Fetch all shares with another user
 			$query = \OC_DB::prepare(
 				'SELECT `share_with`
 				FROM
 				`*PREFIX*share`
 				WHERE
-				`item_source` = ? AND `share_type` = ?'
+				`item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')'
 			);
 
 			$result = $query->execute(array($source, self::SHARE_TYPE_USER));
@@ -180,7 +180,7 @@ class Share {
 				FROM
 				`*PREFIX*share`
 				WHERE
-				`item_source` = ? AND `share_type` = ?'
+				`item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')'
 			);
 
 			$result = $query->execute(array($source, self::SHARE_TYPE_GROUP));
@@ -201,7 +201,7 @@ class Share {
 					FROM
 					`*PREFIX*share`
 					WHERE
-					`item_source` = ? AND `share_type` = ?'
+					`item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')'
 				);
 
 				$result = $query->execute(array($source, self::SHARE_TYPE_LINK));