fixed two bugs in message handling functions