made pseudo code more compact