final version of problem2