Working version of exercise d