Update Envelope.js

Move all 'Prototypes' into Classes, tidy syntax style, fix minor typos, declare undeclared globals