fixed bug with changing matrix