Updated part3 solution.