Nits, please return as earlier as possible:

    if (lock) {
      return;
    }