Fixed a threading related issue that occurs because  is not thread-safe when used from lambdas.