move message type checking to proper place