Updated code to match example from book