solution to ex4, ex5 unpacked