move first bits of marshaler to templates