Tidy up to keygen and marshalling