Added basic thread safety.