Implemented 7-17 in pseudocode