Corrected thread safety issue with dictionary