added better resource check