- Funtctions modified to thread safe.