final version
added forgoten pseudocode