Completed till exercise 1.14 in SICP