Fix bug in ip function