added some of the pseudo code