Added encoding & check for duplicate entries