submitted version, fixed few HW4 bugs