Moved delay change as it generated an exception
Added checking for setDelay