solved exercises 5 and 6 in chapter6