finished pseudocode