changed toperiod to collapse, and size[1] to length