changed N,M structures