Update code as per chapter 6 exercises