Complete ex5(before refactoring)