unit tests and small refactor

Now translating a field to the key in the DB is done always in the DB
layer.