Fixed updating matrix bug