Fixed an infinite loop case in matching.R