changed the way of cost matrix serializing/deserializing