updated solution to problems 4 and 7