excercise 1.7 + some refactoring
exercise 1.7 and some refactoring