fixed problem with message, added correct handling of messages