fixes to db code