Split parent query into two functions