There is very important functionality in checkMessageState, but you've hidden it away at the end of the file in a method with a misleading name.  That method is only ever called once, so it doesn't need to be a separate function.

Basically, this code seems completely broken.  checkMessageState() sounds like some kind of optional assertion thing, so I don't pay much attention to it and it is only until I read all the way down at the bottom that I understand how your logic actually works.

Please get rid of checkMessageState and put it here.