checking in pseudocode based on discussions with Pete