Npe issue

created rebase for #253

Can you please merge these changes?