add a check for unique key being in the record + refactor