tidy up and better serialisation