some bad math, and adjusted duration
scripted update of code from master at b1a3be1 some bad math, and adjusted duration