added null checks to serialisation and unserialisation methods.