Make replacing or adding a query retain the previous order [ARM-542]