Solution for chapter 3