workign version of problem 3