added error checking on read: returns NULL pointer if error occurs in reading matrix