Changed exception handling. Added serialize/deserialize.