Added isset($durations[$i]) in line 172