Refactored some code.
Added function for pretty print of message.