Fixed null pointer issues