Overall identation and polishing
Remade the setlM function (solved bug and optmized complexity)