refactor segment.go, templates.go