psecudocode implementation