ensure that lock is removed in case of exception