fix periodic condition in matching