fixing the use of parameter M for periodic case.