Updating the code with the samples from chapter 2