updating matrix