Code works perfectly for 5x5 matrix