abstracting out the function for generating M and lambda