copied ex5 from textbook