updated solution for ex3