improved loop in function to continue testing if package not found