put all host accesses in null guard

code checks for hosts being null. Put all accesses in the null check, if null is possible otherwise npe as is..