working version of problem 2