Break out delay computation into its own function and add tests, including a regression test for #646. // FREEBIE