pseudocode for worklist algo.