 		WHILE _iterator < _bit_mask_lenght
 		LOOP
 			IF get_bit(_bit_mask, _iterator) = 1 THEN
-				_last_active_bit_index := _iterator;	
+				_last_active_bit_index := _iterator;
 				IF _first_active_bit_index = -1 THEN -- This is the first 1
 					_first_active_bit_index := _iterator;
 					_bit_mask_text := '1';
 				ELSE
 					_bit_mask_text := _bit_mask_text || _segment_bit_mask || '1';
-				END IF;			
+				END IF;
 				_segment_bit_mask := '';
 			ELSE -- current mask value is 0
 				IF _first_active_bit_index != -1 THEN

		SELECT id FROM calendar_element WHERE included_calendar_id = _calendar_id INTO _id;
		IF FOUND THEN
			RAISE EXCEPTION 'You cannot delete or update a calendar %, it is included by some calendar elements', _calendar_id;
		END IF;		
		_bit_mask := getcalendarbitmask(_calendar_id,_start_date,_end_date);
		IF (_bit_mask::text ~ '^0+$') THEN
			FOR _cal_elt IN 
				SELECT * FROM calendar_element WHERE calendar_id = _calendar_id ORDER BY rank DESC
			LOOP
				PERFORM deletecalendarelement(_cal_elt.id);				
			END LOOP;
			UPDATE trip SET period_calendar_id = NULL WHERE period_calendar_id = _calendar_id;
			DELETE FROM calendar_datasource WHERE calendar_id = _calendar_id;
			DELETE FROM calendar WHERE id = _calendar_id;
		ELSE
			PERFORM insertcalendarelement(_calendar_id, _start_date, _end_date, 1, '&'); 
		END IF;
	END;
	$$;

			SELECT * FROM computecalendarsstartend(_calendar_id, _start_date, _end_date, _rank, _operator, _currentElementDeletion, _bit_mask) INTO _computed_date_pair;
			-- Launch same operation an all parent calendars (could have none)
			-- Infinite recursion must not happen because we previously check it with 'detectcalendarinclusionloop' function
			FOR _cal IN
				SELECT id, calendar_id, rank, operator FROM calendar_element WHERE _calendar_id = included_calendar_id
			LOOP
				-- Need to update current calendar element with new calculated values
