proper NPE fix
(cherry picked from commit 74a3c3e963d7b1365025080ae158e3a1fced6eab)