Added a less race prone Lock to the text function.