thread safety fix [#186]