Code for homework #4