Add thread safety to init code