move callback outside of try catch block