added toMatrix() method