refactor gateways