Working version with IP detection