code from Chapter 6 untill paragraph 6.4