--- kernel/classes/datatypes/ezimage/ezimagealiashandler.php
+++ kernel/classes/datatypes/ezimage/ezimagealiashandler.php
@@ -714,124 +714,91 @@
     }
 
     /**
-     * Removes all the image aliases and their information.
-     * The stored images will also be removed if the attribute is the owner
-     * of the images.
+     * Removes aliases from the attribute.
      *
-     * After the images are removed the attribute will containe an internal
-     * structure with empty data
+     * Files, as well as their references in ezimagefile, are only removed if this attribute/version was
+     * the last one referencing it. The attribute's XML is then reset to reference no image.
+     */
+    function removeAliases()
+    {
+        foreach ( $this->aliasList() as $alias )
+        {
+            if ( $alias['is_valid'] )
+                $this->removeAliasFile( $alias['url'] );
+        }
+
+        $this->generateXMLData();
+    }
+
+    /**
+     * Removes $aliasFile and references to it for the attribute.
      *
-     * @param eZContentObjectAttribute $contentObjectAttribute
-     *        Content object attribute to remove aliases for
+     * The eZImageFile entry as well as the file are only removed if this attribute was the last reference.
      *
-     * @return void
+     * @param string $aliasFile
+     *
+     * @return array bool true if something was actually done, false otherwise
      */
-    function removeAliases( $contentObjectAttribute )
+    public function removeAliasFile( $aliasFile )
     {
-        $aliasList = $this->aliasList();
-        $alternativeText = false;
+        if ( $aliasFile == '' )
+            throw new InvalidArgumentException( "Expecting image file path" );
 
-        $contentObjectAttributeVersion = $this->ContentObjectAttributeData['version'];
-        $contentObjectAttributeID = $this->ContentObjectAttributeData['id'];
+        $filePathIsReferencedByOtherAttributes = false;
 
-        $isImageOwner = $this->isImageOwner();
-
-        // We loop over each image alias, and look up the file in ezcontentobject_attribute
-        // Only images referenced by one version will be removed
-        foreach ( $aliasList as $aliasName => $alias )
+        // we must check all eZImageFile referencing the alias file
+        $imageFilesReferencingFilePath = eZImageFile::fetchListByFilepath( $aliasFile );
+        foreach ( $imageFilesReferencingFilePath as $imageFileData )
         {
-            $dirpath = $alias['dirpath'];
-            $doNotDelete = false; // Do not delete files from storage
-
-            if ( $aliasName == 'original' )
-                $alternativeText = $alias['alternative_text'];
-            if ( $alias['is_valid'] )
+            if ( $imageFileData['contentobject_attribute_id'] != $this->ContentObjectAttributeData['id'] )
             {
-                $filepath = $alias['url'];
-
-                /**
-                 * If there are no ezimagefile references to this file with this content object attribute id,
-                 * we are dealing with an attribute that was copied from another content.
-                 * The image doesn't belong to us, and we just don't do anything.
-                 * See http://jira.ez.no/browse/EZP-21324
-                 */
-                if ( !eZImageFile::fetchByFilepath( $contentObjectAttributeID, $filepath ) )
-                    continue;
+                $filePathIsReferencedByOtherAttributes = true;
+            }
 
-                // Fetch ezimage attributes that use $filepath
-                // Always returns current attribute (array of $contentObjectAttributeID and $contentObjectAttributeVersion)
-                $dbResult = eZImageFile::fetchImageAttributesByFilepath( $filepath, $contentObjectAttributeID );
-                $dbResultCount = count( $dbResult );
-                // Check if there are the attributes.
-                if ( $dbResultCount > 0 )
-                {
-                    $doNotDelete = true;
-                    foreach ( $dbResult as $res )
-                    {
-                        // We only look results where the version matches
-                        if ( $res['version'] == $contentObjectAttributeVersion )
-                        {
-                            // If more than one result has been returned, it means
-                            // that another version is using the same image,
-                            // and we should not delete this file
-                            if ( $dbResultCount > 1 )
-                            {
-                                continue;
-                            }
-                            // Only one result means that the current attribute
-                            // & version are the only ones using this image,
-                            // and it can be removed
-                            else
-                            {
-                                $doNotDelete = false;
-                            }
-                        }
+            $imageFileIsReferencedByOtherAttributes = false;
 
-                        eZImageFile::appendFilepath( $res['id'], $filepath, true );
-                    }
-                }
+            // we skip eZImageFile entries that reference another contentobject attribute or another version/language
+            foreach ( eZImageFile::fetchImageAttributesByFilepath( $aliasFile, $imageFileData['contentobject_attribute_id'] ) as $attribute )
+            {
+                if ( $attribute['id'] != $this->ContentObjectAttributeData['id'] )
+                    continue;
 
-                if ( !$doNotDelete )
+                if (
+                    $attribute['version'] != $this->ContentObjectAttributeData['version'] ||
+                    $attribute['language_code'] != $this->ContentObjectAttributeData['language_code']
+                )
                 {
-                    eZImageFile::removeFilepath( $contentObjectAttributeID, $filepath );
-
-                    $file = eZClusterFileHandler::instance( $filepath );
-                    if ( $file->exists() )
-                    {
-                        $file->delete();
-                        eZDir::cleanupEmptyDirectories( $dirpath );
-                    }
-                    else
-                    {
-                        eZDebug::writeError( "Image file $filepath for alias $aliasName does not exist, could not remove from disk", __METHOD__ );
-                    }
+                    $filePathIsReferencedByOtherAttributes = true;
+                    $imageFileIsReferencedByOtherAttributes = true;
+                    break;
                 }
             }
-        }
 
-        $doc = new DOMDocument( '1.0', 'utf-8' );
-        $imageNode = $doc->createElement( "ezimage" );
-        $doc->appendChild( $imageNode );
+            if ( $imageFileIsReferencedByOtherAttributes )
+                continue;
 
-        $imageNode->setAttribute( 'serial_number', false );
-        $imageNode->setAttribute( 'is_valid', false );
-        $imageNode->setAttribute( 'filename', false );
-        $imageNode->setAttribute( 'suffix', false );
-        $imageNode->setAttribute( 'basename', false );
-        $imageNode->setAttribute( 'dirpath', false );
-        $imageNode->setAttribute( 'url', false );
-        $imageNode->setAttribute( 'original_filename', false );
-        $imageNode->setAttribute( 'mime_type', false );
-        $imageNode->setAttribute( 'width', false );
-        $imageNode->setAttribute( 'height', false );
-        $imageNode->setAttribute( 'alternative_text', $alternativeText );
-        $imageNode->setAttribute( 'alias_key', false );
-        $imageNode->setAttribute( 'timestamp', false );
+            // we remove all rows since we can have duplicates
+            eZImageFile::removeObject(
+                eZImageFile::definition(),
+                array(
+                    'contentobject_attribute_id' => $this->ContentObjectAttributeData['id'],
+                    'filepath' => $aliasFile
+                )
+            );
 
-        $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $doc;
-        unset( $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'] );
+        }
 
-        $this->storeDOMTree( $doc, true, $contentObjectAttribute );
+        // remove file, if applicable
+        if ( $filePathIsReferencedByOtherAttributes )
+            return;
+        $file = eZClusterFileHandler::instance( $aliasFile );
+        if ( !$file->exists() )
+        {
+            eZDebug::writeError( "Image file {$aliasFile} does not exist, could not remove from disk", __METHOD__ );
+            return;
+        }
+        $file->delete();
+        eZDir::cleanupEmptyDirectories( dirname( $aliasFile ) );
     }
 
     /*!
--- kernel/classes/datatypes/ezimage/ezimagealiashandler.php
+++ kernel/classes/datatypes/ezimage/ezimagealiashandler.php
@@ -714,124 +714,91 @@
     }
 
     /**
-     * Removes all the image aliases and their information.
-     * The stored images will also be removed if the attribute is the owner
-     * of the images.
+     * Removes aliases from the attribute.
      *
-     * After the images are removed the attribute will containe an internal
-     * structure with empty data
+     * Files, as well as their references in ezimagefile, are only removed if this attribute/version was
+     * the last one referencing it. The attribute's XML is then reset to reference no image.
+     */
+    function removeAliases()
+    {
+        foreach ( $this->aliasList() as $alias )
+        {
+            if ( $alias['is_valid'] )
+                $this->removeAliasFile( $alias['url'] );
+        }
+
+        $this->generateXMLData();
+    }
+
+    /**
+     * Removes $aliasFile and references to it for the attribute.
      *
-     * @param eZContentObjectAttribute $contentObjectAttribute
-     *        Content object attribute to remove aliases for
+     * The eZImageFile entry as well as the file are only removed if this attribute was the last reference.
      *
-     * @return void
+     * @param string $aliasFile
+     *
+     * @return array bool true if something was actually done, false otherwise
      */
-    function removeAliases( $contentObjectAttribute )
+    public function removeAliasFile( $aliasFile )
     {
-        $aliasList = $this->aliasList();
-        $alternativeText = false;
+        if ( $aliasFile == '' )
+            throw new InvalidArgumentException( "Expecting image file path" );
 
-        $contentObjectAttributeVersion = $this->ContentObjectAttributeData['version'];
-        $contentObjectAttributeID = $this->ContentObjectAttributeData['id'];
+        $filePathIsReferencedByOtherAttributes = false;
 
-        $isImageOwner = $this->isImageOwner();
-
-        // We loop over each image alias, and look up the file in ezcontentobject_attribute
-        // Only images referenced by one version will be removed
-        foreach ( $aliasList as $aliasName => $alias )
+        // we must check all eZImageFile referencing the alias file
+        $imageFilesReferencingFilePath = eZImageFile::fetchListByFilepath( $aliasFile );
+        foreach ( $imageFilesReferencingFilePath as $imageFileData )
         {
-            $dirpath = $alias['dirpath'];
-            $doNotDelete = false; // Do not delete files from storage
-
-            if ( $aliasName == 'original' )
-                $alternativeText = $alias['alternative_text'];
-            if ( $alias['is_valid'] )
+            if ( $imageFileData['contentobject_attribute_id'] != $this->ContentObjectAttributeData['id'] )
             {
-                $filepath = $alias['url'];
-
-                /**
-                 * If there are no ezimagefile references to this file with this content object attribute id,
-                 * we are dealing with an attribute that was copied from another content.
-                 * The image doesn't belong to us, and we just don't do anything.
-                 * See http://jira.ez.no/browse/EZP-21324
-                 */
-                if ( !eZImageFile::fetchByFilepath( $contentObjectAttributeID, $filepath ) )
-                    continue;
+                $filePathIsReferencedByOtherAttributes = true;
+            }
 
-                // Fetch ezimage attributes that use $filepath
-                // Always returns current attribute (array of $contentObjectAttributeID and $contentObjectAttributeVersion)
-                $dbResult = eZImageFile::fetchImageAttributesByFilepath( $filepath, $contentObjectAttributeID );
-                $dbResultCount = count( $dbResult );
-                // Check if there are the attributes.
-                if ( $dbResultCount > 0 )
-                {
-                    $doNotDelete = true;
-                    foreach ( $dbResult as $res )
-                    {
-                        // We only look results where the version matches
-                        if ( $res['version'] == $contentObjectAttributeVersion )
-                        {
-                            // If more than one result has been returned, it means
-                            // that another version is using the same image,
-                            // and we should not delete this file
-                            if ( $dbResultCount > 1 )
-                            {
-                                continue;
-                            }
-                            // Only one result means that the current attribute
-                            // & version are the only ones using this image,
-                            // and it can be removed
-                            else
-                            {
-                                $doNotDelete = false;
-                            }
-                        }
+            $imageFileIsReferencedByOtherAttributes = false;
 
-                        eZImageFile::appendFilepath( $res['id'], $filepath, true );
-                    }
-                }
+            // we skip eZImageFile entries that reference another contentobject attribute or another version/language
+            foreach ( eZImageFile::fetchImageAttributesByFilepath( $aliasFile, $imageFileData['contentobject_attribute_id'] ) as $attribute )
+            {
+                if ( $attribute['id'] != $this->ContentObjectAttributeData['id'] )
+                    continue;
 
-                if ( !$doNotDelete )
+                if (
+                    $attribute['version'] != $this->ContentObjectAttributeData['version'] ||
+                    $attribute['language_code'] != $this->ContentObjectAttributeData['language_code']
+                )
                 {
-                    eZImageFile::removeFilepath( $contentObjectAttributeID, $filepath );
-
-                    $file = eZClusterFileHandler::instance( $filepath );
-                    if ( $file->exists() )
-                    {
-                        $file->delete();
-                        eZDir::cleanupEmptyDirectories( $dirpath );
-                    }
-                    else
-                    {
-                        eZDebug::writeError( "Image file $filepath for alias $aliasName does not exist, could not remove from disk", __METHOD__ );
-                    }
+                    $filePathIsReferencedByOtherAttributes = true;
+                    $imageFileIsReferencedByOtherAttributes = true;
+                    break;
                 }
             }
-        }
 
-        $doc = new DOMDocument( '1.0', 'utf-8' );
-        $imageNode = $doc->createElement( "ezimage" );
-        $doc->appendChild( $imageNode );
+            if ( $imageFileIsReferencedByOtherAttributes )
+                continue;
 
-        $imageNode->setAttribute( 'serial_number', false );
-        $imageNode->setAttribute( 'is_valid', false );
-        $imageNode->setAttribute( 'filename', false );
-        $imageNode->setAttribute( 'suffix', false );
-        $imageNode->setAttribute( 'basename', false );
-        $imageNode->setAttribute( 'dirpath', false );
-        $imageNode->setAttribute( 'url', false );
-        $imageNode->setAttribute( 'original_filename', false );
-        $imageNode->setAttribute( 'mime_type', false );
-        $imageNode->setAttribute( 'width', false );
-        $imageNode->setAttribute( 'height', false );
-        $imageNode->setAttribute( 'alternative_text', $alternativeText );
-        $imageNode->setAttribute( 'alias_key', false );
-        $imageNode->setAttribute( 'timestamp', false );
+            // we remove all rows since we can have duplicates
+            eZImageFile::removeObject(
+                eZImageFile::definition(),
+                array(
+                    'contentobject_attribute_id' => $this->ContentObjectAttributeData['id'],
+                    'filepath' => $aliasFile
+                )
+            );
 
-        $this->ContentObjectAttributeData['DataTypeCustom']['dom_tree'] = $doc;
-        unset( $this->ContentObjectAttributeData['DataTypeCustom']['alias_list'] );
+        }
 
-        $this->storeDOMTree( $doc, true, $contentObjectAttribute );
+        // remove file, if applicable
+        if ( $filePathIsReferencedByOtherAttributes )
+            return;
+        $file = eZClusterFileHandler::instance( $aliasFile );
+        if ( !$file->exists() )
+        {
+            eZDebug::writeError( "Image file {$aliasFile} does not exist, could not remove from disk", __METHOD__ );
+            return;
+        }
+        $file->delete();
+        eZDir::cleanupEmptyDirectories( dirname( $aliasFile ) );
     }
 
     /*!
