moved variable to top of try-catch block