Fix race condition in updateHeatmap()