Fixed some potential NPEs.