The routine excludes the chambers being cleaned and scans through the stages in the order of priority until a pair of chambers X and Y are found such that A is an empty chamber in the current highest priority stage and Y is a non-empty chamber (or loadlock) is the stage right before the highest priority stage.