Change function to cack matrix