solution to ex4 added