Improvements to envelope.pyx