added pseudo code