added remaining pseudocode