fixed some message handling bugs