Fixed bug in routing for messages sent out from gateway.