Proper matrix dumping/restoring code