final working code for HW3