Update for language changes and refactor envelopes a bit