refactor the code
add problem 7