macro version of problem 6