moved extractEnvelope behavior to after error checking