Fix serialisation and persistence issues