Refactoring the messages class