Fix some null pointer exceptions