Make SegmentTreeTD template class
More template related changes