ex3 updated with iterator (tested).