Updated IP detection to work properly