Partial homework4, error corrected