do not serialize stuff twice

Little change to reuse the already serialized data (which is used to calculate the size) instead of serializing it again