Updated to with functioning delay function