reference impl. for exercises 58.60,61