Changed iterator task in pmap to a function. Fixes #4035 and #4034