Safeguards. The first line limits the time period to 1000, which is needed for the Median function. The second line limits it to the data that's really available and the third line sets a lower limit for the time period.