Added some exception handling to Matrix constructor