Refactored ex3 & ex4