Refactored envelope handling again
some bugfixes, now works without exceptions thrown
+ some typos/formatting