Improved query_all