corrected pseudocode