Added null check for resource.