diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index 5386de486e190d93aa5671e577d53aa2ba651033..9be3dda7ce3f766a8d62054194bbaa419593952f 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -220,22 +220,10 @@ class Keymanager {
 	 */
 	public static function getFileKey(\OC_FilesystemView $view, $userId, $filePath) {
 
-		// try reusing key file if part file
-		if (self::isPartialFilePath($filePath)) {
-
-			$result = self::getFileKey($view, $userId, self::fixPartialFilePath($filePath));
-
-			if ($result) {
-
-				return $result;
-
-			}
-
-		}
-
 		$util = new Util($view, \OCP\User::getUser());
 
 		list($owner, $filename) = $util->getUidAndFilename($filePath);
+		$filename = self::fixPartialFilePath($filename);
 		$filePath_f = ltrim($filename, '/');
 
 		// in case of system wide mount points the keys are stored directly in the data directory
@@ -424,18 +412,6 @@ class Keymanager {
 	public static function getShareKey(\OC_FilesystemView $view, $userId, $filePath) {
 
 		// try reusing key file if part file
-		if (self::isPartialFilePath($filePath)) {
-
-			$result = self::getShareKey($view, $userId, self::fixPartialFilePath($filePath));
-
-			if ($result) {
-
-				return $result;
-
-			}
-
-		}
-
 		$proxyStatus = \OC_FileProxy::$enabled;
 		\OC_FileProxy::$enabled = false;
 
@@ -443,7 +419,7 @@ class Keymanager {
 		$util = new Util($view, \OCP\User::getUser());
 
 		list($owner, $filename) = $util->getUidAndFilename($filePath);
-
+		$filename = self::fixPartialFilePath($filename);
 		// in case of system wide mount points the keys are stored directly in the data directory
 		if ($util->isSystemWideMountPoint($filename)) {
 			$shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 335ea3733eb2f90565bfe2e2098dbe82876732e3..083b33c03cbf2be40e674a8e509c3d5743975fb7 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -81,7 +81,7 @@ class Stream {
 	 * @return bool
 	 */
 	public function stream_open($path, $mode, $options, &$opened_path) {
-		
+
 		// assume that the file already exist before we decide it finally in getKey()
 		$this->newFile = false;
 
@@ -106,12 +106,12 @@ class Stream {
 		if ($this->relPath === false) {
 			$this->relPath = Helper::getPathToRealFile($this->rawPath);
 		}
-		
+
 		if($this->relPath === false) {
 			\OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to user/files or to user/files_versions', \OCP\Util::ERROR);
 			return false;
 		}
-		
+
 		// Disable fileproxies so we can get the file size and open the source file without recursive encryption
 		$proxyStatus = \OC_FileProxy::$enabled;
 		\OC_FileProxy::$enabled = false;
@@ -188,7 +188,7 @@ class Stream {
 		}
 
 		// Get the data from the file handle
-		$data = fread($this->handle, 8192);
+		$data = fread($this->handle, $count);
 
 		$result = null;
 
@@ -272,7 +272,7 @@ class Stream {
 		} else {
 
 			$this->newFile = true;
-			
+
 			return false;
 
 		}
@@ -296,9 +296,9 @@ class Stream {
 			return strlen($data);
 		}
 
-		// Disable the file proxies so that encryption is not 
-		// automatically attempted when the file is written to disk - 
-		// we are handling that separately here and we don't want to 
+		// Disable the file proxies so that encryption is not
+		// automatically attempted when the file is written to disk -
+		// we are handling that separately here and we don't want to
 		// get into an infinite loop
 		$proxyStatus = \OC_FileProxy::$enabled;
 		\OC_FileProxy::$enabled = false;
@@ -311,7 +311,7 @@ class Stream {
 		$pointer = ftell($this->handle);
 
 		// Get / generate the keyfile for the file we're handling
-		// If we're writing a new file (not overwriting an existing 
+		// If we're writing a new file (not overwriting an existing
 		// one), save the newly generated keyfile
 		if (!$this->getKey()) {
 
@@ -319,7 +319,7 @@ class Stream {
 
 		}
 
-		// If extra data is left over from the last round, make sure it 
+		// If extra data is left over from the last round, make sure it
 		// is integrated into the next 6126 / 8192 block
 		if ($this->writeCache) {
 
@@ -344,12 +344,12 @@ class Stream {
 			if ($remainingLength < 6126) {
 
 				// Set writeCache to contents of $data
-				// The writeCache will be carried over to the 
-				// next write round, and added to the start of 
-				// $data to ensure that written blocks are 
-				// always the correct length. If there is still 
-				// data in writeCache after the writing round 
-				// has finished, then the data will be written 
+				// The writeCache will be carried over to the
+				// next write round, and added to the start of
+				// $data to ensure that written blocks are
+				// always the correct length. If there is still
+				// data in writeCache after the writing round
+				// has finished, then the data will be written
 				// to disk by $this->flush().
 				$this->writeCache = $data;
 
@@ -363,7 +363,7 @@ class Stream {
 
 				$encrypted = $this->preWriteEncrypt($chunk, $this->plainKey);
 
-				// Write the data chunk to disk. This will be 
+				// Write the data chunk to disk. This will be
 				// attended to the last data chunk if the file
 				// being handled totals more than 6126 bytes
 				fwrite($this->handle, $encrypted);
@@ -488,6 +488,7 @@ class Stream {
 				$this->meta['mode'] !== 'rb' &&
 				$this->size > 0
 		) {
+
 			// only write keyfiles if it was a new file
 			if ($this->newFile === true) {
 
@@ -535,6 +536,7 @@ class Stream {
 
 			// set fileinfo
 			$this->rootView->putFileInfo($this->rawPath, $fileInfo);
+
 		}
 
 		return fclose($this->handle);
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 3922f7d9d7f38eb4a9d435adedbbd1d112018667..5d7858569f38d5ea31fb9cb02f7f45e55890c3ac 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -508,10 +508,11 @@ class Util {
 
 			// get the size from filesystem
 			$fullPath = $this->view->getLocalFile($path);
-			$size = filesize($fullPath);
+			$size = $this->view->filesize($path);
 
 			// calculate last chunk nr
 			$lastChunkNr = floor($size / 8192);
+			$lastChunkSize = $size - ($lastChunkNr * 8192);
 
 			// open stream
 			$stream = fopen('crypt://' . $path, "r");
@@ -524,7 +525,7 @@ class Util {
 				fseek($stream, $lastChunckPos);
 
 				// get the content of the last chunk
-				$lastChunkContent = fread($stream, 8192);
+				$lastChunkContent = fread($stream, $lastChunkSize);
 
 				// calc the real file size with the size of the last chunk
 				$realSize = (($lastChunkNr * 6126) + strlen($lastChunkContent));