Database refactoring 2