Made compent finding code more reliable