refactor wrap accessing M and N using get functions, make comments of instance variables and methods