Fixed some null pointer errors