reverted code to be thread safe