Have playSound and sendCookie functions use static local variables in order to keep track of whether process is already under way.