refactored ex3