solved exercise 4 from sw2