Moved delay() function