finished main part of chap 5