Added new matrix generation for LM
refactored