Partial response of problem 3 and fix the problem 2