fixing thread safety issue