Ex3 refactored