change to template & add add_interval method