added missing check for null pointer