Refactoring
Added checking network reachability in gateway