Fix some potential null pointer exceptions