expanding interval code simplified