Completely rewrote the formatDuration function