Minor modifications to the integrate_intervals function, though now appears to have issues with some index. Don't know why, need to resolve this.