Fixes several bugs with delay plans.
Added a test for delay.