add check resource is not null as well