Fixed bugs in RefDB query execution