generic unwrap function