final code for homework 4