Handling some null pointer exceptions