Fixed a bug when delay was > 0 (was using this in a inner function)