Final code for HW3-3