Fix issues with iterator and returning value