added validation for null pointer issues