[#2140] merge svn 5684 and reorder genquery to match specific query which is necessary for managing continuations