added pseudocode