Envelope/Envelope3D tests + bugfixes.