Updated Code to complete part 3