Kairos db

Rebased against latest upstream master.