Added optional thread safety