Added check for null pointer