Sorting the matrix

Signed-off-by: Scuba Steve <sfusaro1@gmail.com>