move lock outside of try/catch