drafted ex 2.27. ex 2.18 & 2.27 still buggy, output is of incorrect form