improve interval function. Adapt new example with new interval function