correcting looping through gateways when sending a command