query history refactored