Fix: better error detection when checking for installed packages