Fix off-by-one error in prefix matching