not final ex 5
a bit refactoring