better serialisation and comparison; code cleanup