Refactoring of challenge 3