Fixed database cleanup on file deletion