Added NPE prevention