Speeded up local matching routine