db fixes
refactoring