replace 1+2N queries with a single query