query helper implementation