Added null pointer exception fixes