Lots of code cleanup and debugs method, similar to what Squid uses