Improved performance for large interval sets and refactored into simpler code