algorithm on page 6 finished