Fully working HW6.