added halfdelay code