Some thread safety added