More refactoring, work on envelopes