updated size function to use iterator