NPE checking

added Checks for NPE