moving callback outside of try/catch