Use iterator for performance reasons. Patch from Jira#2720. Thanks Vikas for review and Surya for providing the patch.