Fix divide by zero error

Fix divide by zero when $duration is zero