Fix potential race condition caused by early unlocking
The lock should be kept between the point we read and the point we write
Also, there is no need to pass SMSPlugin as a parameter, since enclosed classes already have access to their parent by default.