project2: slightly improved pseudocode