initial query code