moving variables into try catch block