improve clearHistory logic