make sorting matrices optional