Add headend function was inside a loop.