Refactored ex2 and ex3 examples