Now it works also with non-square matrix