revised version for HW3