Updated code to use setMatrix function.