fixing possible null pointer issues