Refactor 'merge intervals' again.