added guard condition to gateway;