Fixes bug for timer

I was having trouble with the timeout removal of the messages. I changed the setTimeout function to a self executing anonymous function and it worked.