Refactor on duplicate record exception.