fix two bugs in message handling