added pseudo-code