First "working" version (matlab is nnot stopping because of a wrong operation)