updated pseudo code