more detailed pseudocode