various fixes to marshalling code