Added proper locks and queueing to prevent misordering of messages locally.