Refactor parent query generation and its tests to fix some bugs