Updated code with multithreading and better logging of IP