Database interface hopefully finalised and mostly fixed.