Refactorized 6 for exercise 6