Added more logic to the Gateway.