many db fixes and a couple code fixes