Added thread safety functionality.