not catching NPE, instead added a null check where it was legitimate