Completed the JS for envelopes