add support to fetch history and more compact setup up the deferrend in query