Refactor and first implementation of unique key check (without tests)