Hopefully this will make it much easier to deal with later, and hopefully this
will help to flush out the remaining duration-calculation-related bugs by
avoiding repetition of the calculations. Various minor fixes in the process.
I'm not convinced this is completely bug-free yet, of course, but it does
seem at least to be slightly less broken than before, so.