refactored variable name from m to matrix