Implemented least square method. There is still a bug, that dimension gets over 2