refactored head/body iteration