Fixed issue with query function.