little optimization in query retrieval