Minor fix, NPE checking added