Selecting primary key, saving and transactions fixes