refactor to remove gateways