Rebased version of jmhofer's delay() implementation

This is in response to the request in #384, to rebase the delay() implementation on top of master.