Fixed up query hook to work in replacement mode;