Adds bucketing of physical intervals. Also adds an additional buckets file that stores the data of the buckets. Minor fixes to ensure that streams are closed after writing is complete.