add the code for the rest of problem1