query: import some generic code from borel actions, this needs to be refactored at some point