Fixed a problem with messages not being displayed.
Refactored the code so it's a bit cleaner.