Several fixes to db scripts