Change variable scope

envelope is now accessed in the try catch block