Make sure map[k][i] exists before accessing its elements.