createHistoryQuery function updated