readded gateway check and removed echo debug lines