Optimise match and nmatch