Ok I have this code, and it makes duplicate entries,

I want it to write and log joins in the room, and if it finds a person which joined with the same ip before doesnt add him again, but if he joins with the same nick and a different ip it adds a new entry with the new ip, is this possible ? here is the code

Code:
on *:join:*: {
  if ($read(users.txt,w,$+(*,$address,*))) halt
  elseif ($nick != $me) && (!$read(users.txt,w,* $+ $address($nick,1) $+ *)) { write Users.txt  $address($nick,2) $nick }
}