moved exercise into discussion of generalizing code and reformatted