diff --git a/Telegram/SourceFiles/dropdown.cpp b/Telegram/SourceFiles/dropdown.cpp
index 72588abf2..015a815c1 100644
--- a/Telegram/SourceFiles/dropdown.cpp
+++ b/Telegram/SourceFiles/dropdown.cpp
@@ -1880,11 +1880,15 @@ void StickerPanInner::refreshInlineRows(UserData *bot, const InlineResults &resu
 	int32 count = results.size(), until = 0, untilrow = 0, untilcol = 0;
 	if (!count) {
 		clearInlineRows(resultsDeleted);
-		_showingSavedGifs = true;
 		if (_showingInlineItems) {
-			refreshSavedGifs();
-			emit scrollToY(0);
-			emit scrollUpdated();
+			_showingSavedGifs = cShowingSavedGifs();
+			if (_showingSavedGifs) {
+				refreshSavedGifs();
+				emit scrollToY(0);
+				emit scrollUpdated();
+			} else {
+				showStickerSet(RecentStickerSetId);
+			}
 		}
 		return;
 	}
@@ -2353,6 +2357,7 @@ void StickerPanInner::showStickerSet(uint64 setId) {
 		bool wasNotShowingGifs = !_showingInlineItems;
 		if (wasNotShowingGifs) {
 			_showingInlineItems = true;
+			_showingSavedGifs = true;
 			cSetShowingSavedGifs(true);
 			emit saveConfigDelayed(SaveRecentEmojisTimeout);
 		}
@@ -2394,6 +2399,17 @@ void StickerPanInner::showStickerSet(uint64 setId) {
 	update();
 }
 
+void StickerPanInner::updateShowingSavedGifs() {
+	if (cShowingSavedGifs()) {
+		if (!_showingInlineItems) {
+			_showingSavedGifs = _showingInlineItems = true;
+			if (_inlineRows.isEmpty()) refreshSavedGifs();
+		}
+	} else if (!_showingInlineItems) {
+		_showingSavedGifs = _showingInlineItems = false;
+	}
+}
+
 void StickerPanInner::showFinish() {
 	if (_showingInlineItems && _showingSavedGifs) {
 		_setGifCommand = App::insertBotCommand((cTestMode() ? qstr("@contextbot") : qstr("@gif")), true);
@@ -3437,6 +3453,8 @@ void EmojiPan::onSwitch() {
 			s_inner.showStickerSet(DefaultStickerSetId);
 		} else if (!cShowingSavedGifs() && !cSavedGifs().isEmpty() && cStickerSets().isEmpty()) {
 			s_inner.showStickerSet(NoneStickerSetId);
+		} else {
+			s_inner.updateShowingSavedGifs();
 		}
 		if (cShowingSavedGifs()) {
 			s_inner.showFinish();
diff --git a/Telegram/SourceFiles/dropdown.h b/Telegram/SourceFiles/dropdown.h
index 72254b9b4..b86a1d6f2 100644
--- a/Telegram/SourceFiles/dropdown.h
+++ b/Telegram/SourceFiles/dropdown.h
@@ -336,6 +336,7 @@ public:
 	void hideFinish(bool completely);
 	void showFinish();
 	void showStickerSet(uint64 setId);
+	void updateShowingSavedGifs();
 
 	bool showSectionIcons() const;
 	void clearSelection(bool fast = false);
diff --git a/Telegram/SourceFiles/gui/animation.cpp b/Telegram/SourceFiles/gui/animation.cpp
index 54c70a20e..79c64b8d3 100644
--- a/Telegram/SourceFiles/gui/animation.cpp
+++ b/Telegram/SourceFiles/gui/animation.cpp
@@ -268,9 +268,9 @@ ClipReader::Frame *ClipReader::frameToWrite() const { // 0 means not ready
 	return _frames + (((step + 3) / 2) % 3);
 }
 
-ClipReader::Frame *ClipReader::frameToRequestOther() const {
+ClipReader::Frame *ClipReader::frameToRequestOther(bool check) const {
 	int32 step = _step.loadAcquire();
-	if (step == FirstFrameNotReadStep || step == WaitingForRequestStep) {
+	if (step == FirstFrameNotReadStep || step == WaitingForRequestStep || (check && (step % 2))) {
 		return 0;
 	}
 	return _frames + (((step + 5) / 2) % 3);
@@ -347,9 +347,8 @@ QPixmap ClipReader::current(int32 framew, int32 frameh, int32 outerw, int32 oute
 	QImage cache;
 	frame->pix = _prepareFrame(frame->request, frame->original, cache, true);
 
-	Frame *other = frameToRequestOther();
-	t_assert(other != 0);
-	other->request = frame->request;
+	Frame *other = frameToRequestOther(true);
+	if (other) other->request = frame->request;
 
 	moveToNextShow();
 
@@ -1056,17 +1055,18 @@ bool ClipReadManager::handleProcessResult(ClipReaderPrivate *reader, ClipProcess
 		_loadLevel.fetchAndAddRelaxed(reader->_width * reader->_height - AverageGifSize);
 	}
 	if (!reader->_paused && (result == ClipProcessRepaint || result == ClipProcessWait)) {
-		ClipReader::Frame *frame = it.key()->frameToWrite(), *other = it.key()->frameToRequestOther();
+		ClipReader::Frame *frame = it.key()->frameToWrite(), *other = it.key()->frameToRequestOther(false);
 		t_assert(frame != 0 && other != 0);
 		if (qMax(frame->when, other->when) + WaitBeforeGifPause < qMax(reader->_previousMs, ms)) {
 			reader->_paused = true;
-			it.key()->_paused.storeRelease(true);
+			it.key()->_paused.storeRelease(1);
 			result = ClipProcessReinit;
 		}
 	}
 	if (result == ClipProcessReinit || result == ClipProcessRepaint || result == ClipProcessStarted) {
 		ClipReader::Frame *frame = it.key()->frameToWrite();
 		t_assert(frame != 0);
+		frame->pix = QPixmap();
 		frame->pix = reader->_current;
 		frame->original = reader->_currentOriginal;
 		frame->displayed = false;
diff --git a/Telegram/SourceFiles/gui/animation.h b/Telegram/SourceFiles/gui/animation.h
index 729848209..4ae1fa8e1 100644
--- a/Telegram/SourceFiles/gui/animation.h
+++ b/Telegram/SourceFiles/gui/animation.h
@@ -491,30 +491,6 @@ struct ClipFrameRequest {
 	bool rounded;
 };
 
-template <typename Type>
-class Atomic {
-public:
-
-	Atomic(const Type &value = Type()) : _value(value) {
-	}
-
-	Type get() const {
-		QReadLocker lock(&_lock);
-		Type result = _value;
-		return result;
-	}
-
-	void set(const Type &value) {
-		QWriteLocker lock(&_lock);
-		_value = value;
-	}
-
-private:
-	Type _value;
-	mutable QReadWriteLock _lock;
-
-};
-
 enum ClipReaderNotification {
 	ClipReaderReinit,
 	ClipReaderRepaint,
@@ -596,7 +572,7 @@ private:
 	mutable Frame _frames[3];
 	Frame *frameToShow() const; // 0 means not ready
 	Frame *frameToWrite() const; // 0 means not ready
-	Frame *frameToRequestOther() const;
+	Frame *frameToRequestOther(bool check) const;
 	void moveToNextShow() const;
 	void moveToNextWrite() const;
 
diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp
index cdb995846..18da2d243 100644
--- a/Telegram/SourceFiles/historywidget.cpp
+++ b/Telegram/SourceFiles/historywidget.cpp
@@ -3500,6 +3500,10 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
 	} else {
 		doneShow();
 	}
+	if (_inlineBot) {
+		_inlineBot = 0;
+		_emojiPan.clearInlineBot();
+	}
 
 	if (App::wnd()) QTimer::singleShot(0, App::wnd(), SLOT(setInnerFocus()));
 
@@ -4833,12 +4837,14 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) {
 	if (!_history) return false;
 
 	QString toInsert = cmd;
-	PeerData *bot = _peer->isUser() ? _peer : (App::hoveredLinkItem() ? (App::hoveredLinkItem()->toHistoryForwarded() ? App::hoveredLinkItem()->toHistoryForwarded()->fromForwarded() : App::hoveredLinkItem()->from()) : 0);
-	if (!bot->isUser() || !bot->asUser()->botInfo) bot = 0;
-	QString username = bot ? bot->asUser()->username : QString();
-	int32 botStatus = _peer->isChat() ? _peer->asChat()->botStatus : (_peer->isMegagroup() ? _peer->asChannel()->mgInfo->botStatus : -1);
-	if (toInsert.indexOf('@') < 0 && !username.isEmpty() && (botStatus == 0 || botStatus == 2)) {
-		toInsert += '@' + username;
+	if (!toInsert.isEmpty() && toInsert.at(0) != '@') {
+		PeerData *bot = _peer->isUser() ? _peer : (App::hoveredLinkItem() ? (App::hoveredLinkItem()->toHistoryForwarded() ? App::hoveredLinkItem()->toHistoryForwarded()->fromForwarded() : App::hoveredLinkItem()->from()) : 0);
+		if (!bot->isUser() || !bot->asUser()->botInfo) bot = 0;
+		QString username = bot ? bot->asUser()->username : QString();
+		int32 botStatus = _peer->isChat() ? _peer->asChat()->botStatus : (_peer->isMegagroup() ? _peer->asChannel()->mgInfo->botStatus : -1);
+		if (toInsert.indexOf('@') < 0 && !username.isEmpty() && (botStatus == 0 || botStatus == 2)) {
+			toInsert += '@' + username;
+		}
 	}
 	toInsert += ' ';
 
diff --git a/Telegram/SourceFiles/localstorage.cpp b/Telegram/SourceFiles/localstorage.cpp
index c5ea7381c..de6800d5b 100644
--- a/Telegram/SourceFiles/localstorage.cpp
+++ b/Telegram/SourceFiles/localstorage.cpp
@@ -609,7 +609,7 @@ namespace {
 		if (!_working()) return;
 
 		_manager->writingLocations();
-		if (_fileLocations.isEmpty()) {
+		if (_fileLocations.isEmpty() && _webFilesMap.isEmpty()) {
 			if (_locationsKey) {
 				clearKey(_locationsKey);
 				_locationsKey = 0;