Add lock to be thread-safe