Fixed bug in matching query