Refactor the squid autodetect code

Refactor the code into its own function, cleaner.